//
//  ViewController.swift
//  Localized
//
//  Created by YC on 2017/7/5.
//  Copyright © 2017年 YC. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var testLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let t = LocalizedStrings("Name")
        NSLog("%@", t)
        
        let name = NSLocalizedString("Name", comment: "123")
        NSLog("%@", name)
        
        let test = NSLocalizedString("Test", tableName: "Test", comment: "")
        NSLog("%@", test)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func LocalizedStrings(_ key: String) -> String {
        let resourcePath: String?
        
        if let frameworkBundle = Bundle(identifier: "com.YC.Localized") {
            // Load from Framework
            resourcePath = frameworkBundle.resourcePath
        } else {
            // Load from Main Bundle
            resourcePath = Bundle.main.resourcePath
        }
        
        if resourcePath == nil {
            return ""
        }
        
        let path = URL(fileURLWithPath: resourcePath!).appendingPathComponent("Settings.bundle")
        guard let bundle = Bundle(url: path) else {
            return ""
        }
        
        return NSLocalizedString(key, tableName: "Root", bundle: bundle, comment: "")
    }

}

